#include <iostream>
#include "Slave.h"
#include <mpi.h>

using namespace std;


class MySlave : public Slave{

	public:		
		void Operation(char* inputBuffer, int size){
			
		}
		
};


int main(int argc, char *argv[]){
	int pool_size, my_rank;

	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &pool_size);
	MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
	
	printf("Initialized node: %d of %d\n", my_rank, pool_size);

	// poki co, testowe wyslanie 
	if (my_rank==0){
		MPI_Request request;
		MPI_Status status;
		
		char jobBuffer[1024];
		int tag = TAG_JOB;
		
		for(int i=1; i<pool_size; i++){
			MPI_Isend (jobBuffer, sizeof(jobBuffer), MPI_CHAR,
					   i, tag, MPI_COMM_WORLD, &request);
			MPI_Wait (&request, &status);
		}
	}
	
	// Slaves
	if (my_rank!=0){
		MySlave* mySlave = new MySlave();
		mySlave->SetParameters(my_rank, 1024);
		mySlave->Start();
	}		
		
	MPI_Finalize();
}
